package com.hmall.api.config;

import com.hmall.api.client.fallbackFactory.ItemClientFallbackFactory;
import com.hmall.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

import java.util.Collection;

public class defaultClientConfig {

    @Bean
    public Logger.Level defaultLogConfig(){
        return Logger.Level.NONE;
    }

    @Bean
    public RequestInterceptor requestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                // 传递用户信息
                Long userId = UserContext.getUser();
                if(userId != null){
                    requestTemplate.header("user-info", userId.toString());
                }

                // 传递token
//                String token = requestTemplate.getRequestVariables("authorization");


            }
        };
    }

    @Bean
    public ItemClientFallbackFactory itemClientFallbackFactory(){
        return new ItemClientFallbackFactory();
    }
}
